<!-- 需求添加、编辑页面 -->
<template>
  <div class="right">
    <div class="right-timeline">
      <h2 class="title" style="text-align: center">审核流程</h2>
      <div class="status" style="text-align: center">
        <a-button shape="round">优先级：中</a-button>
      </div>

      <a-timeline>
        <a-timeline-item v-for="(item, index) in data" :key="index">
          <template #dot>
            <icon-check-circle-fill
              :style="{
                fontSize: '22px',
                padding: '2px',
                boxSizing: 'border-box',
                borderRadius: '50%',
                backgroundColor: 'var(--color-primary-light-1)',
              }"
            />
          </template>
          <div class="card" v-show="item.flowNodeType === 1">
            <div
              class="info"
              style="display: flex; justify-content: space-between"
            >
              <div>
                <div> 开始 </div>
              </div>
              <div @click="item.show = !item.show">
                <span style="font-weight: solid">{{
                  item.show ? '收起' : '展开'
                }}</span>
                <icon-down v-show="!item.show" />
                <icon-up v-show="item.show" />
              </div>
            </div>
            <div v-show="item.show" class="info-text">
              <a-space class="text-item"
                ><div>发起人：{{ item.createName }}</div
                ><div>{{ item.createPosition }}</div>
                <div class="ispass1">
                  <icon-check-circle-fill />
                  已提交
                </div></a-space
              >
            </div>
          </div>
          <div class="card" v-show="item.flowNodeType === 2">
            <div
              class="info"
              style="display: flex; justify-content: space-between"
            >
              <div>
                <div> 审核人 </div>
              </div>
              <div @click="item.show = !item.show">
                <span style="font-weight: solid">{{
                  item.show ? '收起' : '展开'
                }}</span>
                <icon-down v-show="!item.show" />
                <icon-up v-show="item.show" />
              </div>
            </div>
            <div v-show="item.show" class="info-text">
              <a-space :size="10" direction="vertical" class="text-item"
                ><div
                  ><a-space
                    ><div>待</div
                    ><div>{{
                      item.reviewedBy === use.id ? '我' : item.reviewedName
                    }}</div
                    ><div>审批</div></a-space
                  ></div
                ><div
                  ><a-space :size="30"
                    ><div style="">审批状态:</div
                    ><div
                      :class="
                        item.state === 0
                          ? 'wait'
                          : item.state === 1
                          ? 'Examining'
                          : item.state === 2
                          ? 'pass'
                          : 'NoPass'
                      "
                      >{{
                        item.state === 0
                          ? '待审批'
                          : item.state === 1
                          ? '审批中'
                          : item.state === 2
                          ? '同意'
                          : '不同意'
                      }}</div
                    ></a-space
                  ></div
                ><div
                  ><a-space direction="vertical" style="width: 100%"
                    ><div>审批意见:</div>
                    <a-textarea v-model="item.remark" placeholder="无" disabled
                  /></a-space> </div
              ></a-space>
            </div>
          </div>
        </a-timeline-item>
      </a-timeline>
    </div>
    <div v-show="props.isProcess" class="right-bottom">
      <div class="right-bottom-text">审核人：待 我审核</div>
      <a-space>
        <a-button-group>
          <a-button type="outline" status="success" @click="statusClick(2)">
            <template #icon>
              <icon-check-circle-fill
                size="20"
                class="icon"
                v-show="finalAudit.state === 1"
              />
              <span v-show="finalAudit.state !== 1"> </span>
            </template>
          </a-button>

          <a-button type="primary" status="success" @click="statusClick(2)">
            确认
          </a-button>
        </a-button-group>
        <a-button-group>
          <a-button type="outline" status="danger" @click="statusClick(3)">
            <template #icon>
              <icon-check-circle-fill
                size="20"
                class="icon"
                v-show="finalAudit.state === 3"
              />
              <span v-show="finalAudit.state !== 3"> </span>
            </template>
          </a-button>
          <a-button type="primary" status="danger" @click="statusClick(3)">
            驳回
          </a-button>
        </a-button-group>
      </a-space>
    </div>
  </div>
  <a-modal :mask-closable="false" v-model:visible="visible" title-align="start">
    <template #title>
      {{ title }}
    </template>
    <div>
      <a-textarea
        v-model="finalAudit.remark"
        style="min-height: 100px"
        placeholder="请填写审核意见（选填）"
        auto-size
      />
    </div>
    <template #footer>
      <div class="footer">
        <!-- <div class="footer-upload">
            <a-button type="primary">
              <template #icon>
                <icon-upload />
              </template>
              上传附件
            </a-button>
          </div> -->
        <div class="footer-btn">
          <a-space>
            <a-button @click="visible = false">取消</a-button>
            <a-button type="primary" @click="subOk">确定</a-button>
          </a-space>
        </div>
      </div>
    </template>
  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, reactive, watchEffect, computed } from 'vue';
  import { postBasisFlowAudit } from '@/api/home/System settings/basis-flow';
  import { IconUser } from '@arco-design/web-vue/es/icon';

  const use = JSON.parse(sessionStorage.getItem('loginInfo') as any);
  interface TData {
    approved: any[];
    flowAuditData: any;
    isProcess: boolean;
  }
  const props = withDefaults(defineProps<TData>(), {});

  const data = computed(() => {
    return props.approved;
  });

  const finalAudit = ref<any>({
    orderDemandBy: undefined,
    reviewedBy: undefined,
    state: undefined,
    remark: '',
  });
  const emit = defineEmits(['finalAudit']);
  const visible = ref(false);
  const title = ref('');

  const approvedData = computed(() => {
    return props.flowAuditData;
  });

  const statusClick = (status: number) => {
    visible.value = true;
    title.value =
      status === 2 ? '确定同意"客户需求"吗？' : '确定拒绝"客户需求"吗？';
    finalAudit.value.state = status;
  };

  const subOk = async () => {
    finalAudit.value.orderDemandBy = props.flowAuditData[0].orderDemandBy;
    finalAudit.value.reviewedBy = use.id;
    emit('finalAudit', finalAudit.value);
    visible.value = false;
  };
</script>

<style scoped lang="less">
  .right {
    // height: calc(100vh - 300px);
    width: 30%;
    height: 600px;
    // overflow: auto;
    margin: 15px;
    display: flex;
    flex-direction: column;
    box-shadow: 1px 1px 5px rgb(102 102 102 / 35%);
    border-radius: 5px;

    &-timeline {
      // height: 300px;
      // flex: 1;
      overflow: auto;
      padding: 0 16px;

      .card {
        .info {
          &-staff {
            padding: 5px;
            display: flex;
            justify-content: space-between;

            &-name {
              display: flex;
            }

            &-opration {
              color: #165dff;
              cursor: pointer;
            }
          }

          .status {
            color: #ccc;
            margin-left: 16px;
          }
        }

        .text {
          margin-top: 16px;
          border-bottom: 1px solid #eee;
          margin-bottom: 16px;
          background: #f9f9f9;
          border-radius: 5px;
          padding: 8px;

          .staff-item {
            .node {
              margin-right: 16px;
            }

            // .ispass1 {
            //   border: #00b42a solid 1px;
            //   padding: 0 5px;
            //   border-radius: 2px;
            //   color: #00b42a;
            // }

            .ispass2 {
              border: #f53f3f solid 1px;
              padding: 0 5px;
              border-radius: 2px;
              color: #f53f3f;
            }

            .ispass3 {
              border: #a0a2a7 solid 1px;
              padding: 0 5px;
              border-radius: 2px;
              color: #a0a2a7;
            }
          }

          .opinion {
            padding: 5px 10px;
            font-size: 12px;
            color: #888;
            border: #eee solid 1px;
          }

          .file {
            margin: 10px 0;
            display: flex;

            &-item {
              display: flex;
              flex-direction: column;
            }
          }
        }
      }
    }

    .right-bottom {
      padding: 16px;
      border-top: #eee solid 1px;

      &-text {
        margin-bottom: 10px;
      }

      span {
        border-radius: 50%;
        height: 18px;
        width: 18px;
        border: #ccc 1px solid;
      }
    }
  }
  .info-text {
    margin: 10px;
    width: 95%;
    // height: 100px;
    background: inherit;
    padding: 5px;
    background-color: rgba(249, 249, 249, 1);
    border: none;
    border-radius: 2px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    // line-height: 50px;
    .ispass1 {
      width: 78px;
      height: 23px;
      padding: 0 5px;
      background: inherit;
      background-color: rgba(49, 194, 124, 0.149019607843137);
      border: none;
      color: #31c27c;
    }
    .ispass3 {
      width: 78px;
      height: 23px;
      border: #a0a2a7 solid 1px;
      padding: 0 5px;
      border-radius: 2px;
      color: #a0a2a7;
    }
    .text-item {
      width: 100%;
      padding: 10px;
    }
  }

  .Examining {
    // 审核中
    color: #165dff;
  }
  .footer {
    display: flex;
    justify-content: space-between;
  }
  .wait {
    color: #a0a2a7;
  }
  .pass {
    color: #31c27c;
  }
  .NoPass {
    color: #f53f3f;
  }

  // :deep (.arco-space),
  // :deep (.arco-space-vertical) {
  //   width: 100%;
  // }
</style>
